<template>
  <div>
    <Form :model="formItem">
      <Row :gutter="24">
        <Col span="8">
          <FormItem>
            <template #label>
              <span style="color: red">*</span><span>工作单位：</span>
            </template>
            <Input maxlength="30" :disabled="formItem.operation === '2'" v-model="formItem.work_address"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem>
            <template #label>
              <span style="color: red">*</span><span>住房性质：</span>
            </template>
            <Input maxlength="10" :disabled="formItem.operation === '2'" v-model="formItem.zf_type"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem>
            <template #label>
              <span style="color: red">*</span><span>居住楼房/平房：</span>
            </template>
            <Input maxlength="10" :disabled="formItem.operation === '2'" v-model="formItem.jz_type"></Input>
          </FormItem>
        </Col>
      </Row>
      <Row :gutter="24">
        <Col span="24">
          <FormItem>
            <template #label>
              <span style="color: red">*</span><span>取暖救助报销地址：</span>
            </template>
            <div class="inputClass">
              <Select :disabled="formItem.operation === '2'" v-model="formItem.city" placeholder="选择区" style="width: 15%;padding-right: 5px" @on-change="getMailListInfo(formItem.city, 'streetList')">
                <Option v-for="item in arrayData.cityList" :value="JSON.stringify(item)" :key="item.id">{{ item.name }}</Option>
              </Select>
              <Select :disabled="formItem.operation === '2'" v-model="formItem.street" placeholder="选择街道"  style="width: 15%;padding-right: 5px" @on-change="getMailListInfo(formItem.street, 'communityList')">
                <Option v-for="item in arrayData.streetList" :value="JSON.stringify(item)" :key="item.id">{{ item.name }}</Option>
              </Select>
              <Select :disabled="formItem.operation === '2'" v-model="formItem.community" placeholder="选择社区" style="width: 15%;padding-right: 5px">
                <Option v-for="item in arrayData.communityList" :value="JSON.stringify(item)" :key="item.id">{{ item.name }}</Option>
              </Select>
              <Input maxlength="50" :disabled="formItem.operation === '2'" v-model="formItem.d_address" placeholder="详细地址" style="width: 55%"></Input>
            </div>
          </FormItem>
        </Col>
      </Row>
      <Row :gutter="24">
        <Col span="8">
          <FormItem>
            <template #label>
              <span>补贴标准(元)：</span>
            </template>
            <RadioGroup v-model="formItem.subsidy_mode" @on-change="updateSubsidyRmb">
              <Radio style="margin-right: 20px" :disabled="formItem.operation === '2'" :label="'180'">180</Radio >
              <Radio style="margin-right: 20px" :disabled="formItem.operation === '2'" :label="'300'">300</Radio >
              <Radio style="margin-right: 20px" :disabled="formItem.operation === '2'" :label="'420'">420</Radio >
              <Radio style="margin-right: 20px" :disabled="formItem.operation === '2'" :label="'700'">700</Radio >
            </RadioGroup >
<!--            <Input disabled v-model="formItem.subsidy_mode"></Input>-->
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem>
            <template #label>
              <span>补贴采暖费金额(元)：</span>
            </template>
            <Input disabled v-model="formItem.subsidy_rmb"></Input>
          </FormItem>
        </Col>
      </Row>
      <Row :gutter="24">
        <Col span="24">
          <FormItem label="备注">
            <Input maxlength="300" show-word-limit :disabled="formItem.operation === '2'" type="textarea" v-model="formItem.cn_rmb_all"></Input>
          </FormItem>
        </Col>
      </Row>
    </Form>
  </div>
</template>
<script>
import { postCN } from '@/api/eventlist'

export default {
  props: {
    paramsData: Object
  },
  data () {
    return {
      list: [],
      formItem: {},
      arrayData: {}
    }
  },
  methods: {
    getMailListInfo (param, list) {
      let paramData = {}
      if (param) {
        paramData = JSON.parse(param)
      }
      let data = {
        method: 'findDownList',
        pid: paramData.id
      }
      postCN(data).then(res => {
        if (list === 'streetList') {
          this.formItem.street = ''
          this.formItem.community = ''
        }
        if (list === 'communityList') {
          this.formItem.community = ''
        }
        this.$set(this.arrayData, list, res.data.data.downList)
      })
    },
    getMailList (param, list) {
      let paramData = JSON.parse(param)
      let data = {
        method: 'findDownList',
        pid: paramData.id
      }
      let that = this
      postCN(data).then(res => {
        if (res.data.errcode === 0) {
          // list = res.data.data.downList
          that.$set(that.arrayData, list, res.data.data.downList)
          if (that.formItem.area) {
            that.arrayData.cityList.forEach(function (item) {
              if (item.name === that.formItem.area) {
                that.formItem.city = JSON.stringify(item)
                that.getMailList2(that.formItem.city, 'streetList')
              }
            })
          }
        }
      })
    },
    getMailList2 (param, list) { // 查询街道
      let paramData = JSON.parse(param)
      let data = {
        method: 'findDownList',
        pid: paramData.id
      }
      let that = this
      postCN(data).then(res => {
        if (res.data.errcode === 0) {
          that.$set(this.arrayData, list, res.data.data.downList)
          that.arrayData.streetList.forEach(function (item) {
            if (item.name === that.formItem.street) {
              that.formItem.street = JSON.stringify(item)
              that.getMailList3(that.formItem.street, 'communityList')
            }
          })
        }
      })
    },
    getMailList3 (param, list) {
      let paramData = JSON.parse(param)
      let data = {
        method: 'findDownList',
        pid: paramData.id
      }
      postCN(data).then(res => {
        if (res.data.errcode === 0) {
          this.$set(this.arrayData, list, res.data.data.downList)
          let that = this
          that.arrayData.communityList.forEach(function (item) {
            if (item.name === that.formItem.community) {
              that.formItem.community = JSON.stringify(item)
            }
          })
        }
      })
    },
    clearInfo () {
      this.formItem = {
        ...this.paramsData,
        fc_m2: '',
        subsidy_rmb: '',
        subsidy_mode: '',
        persion_rmb: ''
      }
    },
    getUserInfo () {
      let data = {
        method: 'selectUserType',
        card_no: this.formItem.person_card_no,
        // card_no: '211382199611083135',
        // type: '1'
        type: this.formItem.type,
        check: '1'
      }
      postCN(data).then(res => {
        if (res.data.errcode === 0) {
          let formItem = {
            settingList: res.data.data.settingList
          }
          this.formItem.settingList = formItem.settingList
          let that = this
          if (formItem.settingList && !that.formItem.subsidy_mode) {
            formItem.settingList.forEach(function (item) {
              if (item.type_dictionary === 'FSDB' && that.paramsData.subsidy_type === '120') {
                that.formItem.subsidy_mode = item.three_dictionary
                that.formItem.subsidy_rmb = item.three_dictionary
              }
              if (item.type_dictionary === 'FSTK' && that.paramsData.subsidy_type === '150') {
                that.formItem.subsidy_mode = item.three_dictionary
                that.formItem.subsidy_rmb = item.three_dictionary
              }
              if (item.type_dictionary === 'FSNC' && that.paramsData.subsidy_type === '110') {
                that.formItem.subsidy_mode = item.three_dictionary
                that.formItem.subsidy_rmb = item.three_dictionary
              }
              if (item.type_dictionary === 'FSGY' && that.paramsData.subsidy_type === '140') {
                that.formItem.subsidy_mode = item.three_dictionary
                that.formItem.subsidy_rmb = item.three_dictionary
              }
              if (item.type_dictionary === 'FSCHBY' && that.paramsData.subsidy_type === '610') {
                that.formItem.subsidy_mode = item.three_dictionary
                that.formItem.subsidy_rmb = item.three_dictionary
              }
              if (item.type_dictionary === 'FSNCBY' && that.paramsData.subsidy_type === '620') {
                that.formItem.subsidy_mode = item.three_dictionary
                that.formItem.subsidy_rmb = item.three_dictionary
              }
            })
          }
        } else {
          this.$Notice.error({
            title: '订单创建失败',
            desc: res.data.errmsg
          })
          this.$router.go(-1)
        }
      })
    },
    updateSubsidyRmb () {
      this.formItem.subsidy_rmb = this.formItem.subsidy_mode
    }
  },
  mounted () {
    let data = {
      id: '2'
    }
    this.formItem = this.paramsData
    if (!this.paramsData.d_address) {
      let address = this.paramsData.address.replace(' ', '')
      address = address.replace('辽宁省', '')
      address = address.replace('沈阳市', '')
      this.formItem.d_address = address
      this.formItem.a_address = address
    } else {
      let address = this.paramsData.address.replace('辽宁省', '')
      address = address.replace('沈阳市', '')
      address = address.replace(' ', '')
      this.formItem.a_address = address
    }
    data = JSON.stringify(data)
    this.getMailList(data, 'cityList')
    if (!this.formItem.operation) {
      this.clearInfo()
    }
    if (!this.formItem.operation || this.formItem.operation === '1') {
      console.log('进来了啦啦啦啦啦啦啦啦2')
      let that = this
      // this.clearInfo()
      if (that.formItem.settingList && !that.formItem.subsidy_mode) {
        that.formItem.settingList.forEach(function (item) {
          if (item.type_dictionary === 'FSDB' && that.paramsData.subsidy_type === '120') {
            that.formItem.subsidy_mode = item.three_dictionary
            that.formItem.subsidy_rmb = item.three_dictionary
          }
          if (item.type_dictionary === 'FSTK' && that.paramsData.subsidy_type === '150') {
            that.formItem.subsidy_mode = item.three_dictionary
            that.formItem.subsidy_rmb = item.three_dictionary
          }
          if (item.type_dictionary === 'FSNC' && that.paramsData.subsidy_type === '110') {
            that.formItem.subsidy_mode = item.three_dictionary
            that.formItem.subsidy_rmb = item.three_dictionary
          }
          if (item.type_dictionary === 'FSGY' && that.paramsData.subsidy_type === '140') {
            that.formItem.subsidy_mode = item.three_dictionary
            that.formItem.subsidy_rmb = item.three_dictionary
          }
          if (item.type_dictionary === 'FSCHBY' && that.paramsData.subsidy_type === '610') {
            that.formItem.subsidy_mode = item.three_dictionary
            that.formItem.subsidy_rmb = item.three_dictionary
          }
          if (item.type_dictionary === 'FSNCBY' && that.paramsData.subsidy_type === '620') {
            that.formItem.subsidy_mode = item.three_dictionary
            that.formItem.subsidy_rmb = item.three_dictionary
          }
        })
      } else {
        this.getUserInfo()
      }
    } else {
      this.getUserInfo()
    }
  }
}
</script>
<style></style>
